package com.lin.sms.page;

public class PageIndex {

    private Integer beginIndex;
    private Integer endIndex;
    
    /**
     * @param indexCount 要显示的索引总数
     * @param currentPage 当前页
     * @param totalPage 总页数
     */
    
    //定义一个构造器设置beginIndex, 和endIndex的值
    public  PageIndex (Integer indexCount, 
        Integer currentPage, Integer totalPage) {
        //判断总页数是否比要显示的总索引数小, 如果小的话,beginIndex = 1,endIndex = totalPage;
        if (totalPage < indexCount) {
            beginIndex = 1;
            endIndex = totalPage;
        } else {//否则的话,当前页放在索引数中间
        beginIndex = currentPage - indexCount / 2;
        endIndex = currentPage + (indexCount % 2 ==0 ? indexCount / 2 - 1 : indexCount / 2);
        //判断beginIndex是否小于1,小于1是不允许的,所有要beginIndex要赋值为1
        if (beginIndex < 1) {
            beginIndex = 1;
            endIndex = indexCount;
        } 
        if (endIndex > totalPage) {
            endIndex = totalPage;
            beginIndex = endIndex - indexCount;
        }
        }
    }

    public Integer getBeginIndex() {
        return beginIndex;
    }

    public Integer getEndIndex() {
        return endIndex;
    }
    
    
}
